package com.blkj.iam.common.util;

import java.security.SecureRandom;
import java.util.Random;

/**
 * @author hujingbo
 */
public class ClientUtils {

    private static final Random random = new SecureRandom();

    // 生成 8 位数字的 appId
    public static String generateAppId() {
        // 生成一个 8 位数字
        long appId = Math.abs(random.nextLong()) % 100_000_000L;
        return String.format("%08d", appId);
    }

    // 生成 32 位随机字符串的 appKey
    public static String generateAppKey() {
        // 定义字符集
        String characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder appKey = new StringBuilder(32);

        // 生成 32 位随机字符串
        for (int i = 0; i < 32; i++) {
            int index = random.nextInt(characters.length());
            appKey.append(characters.charAt(index));
        }

        return appKey.toString();
    }

    public static void main(String[] args) {
        // 生成 appId 和 appKey
        String appId = generateAppId();
        String appKey = generateAppKey();

        System.out.println("Generated appId: " + appId);
        System.out.println("Generated appKey: " + appKey);
    }
}
